package com.example.administrator.android01app;

import android.app.WallpaperManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

public class Ch4Activity2 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_ch4_2);

        final ImageView imageView=(ImageView)findViewById(R.id.ch4_2_iv);
        //使用内部匿名类进行监听器注册
        imageView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                WallpaperManager wallpaperManager=(WallpaperManager)getSystemService(WALLPAPER_SERVICE);
                try{
                    wallpaperManager.setResource(R.raw.abcd);

                }catch (Exception e){
                    Log.e(Ch4Activity2.class.toString(),e.toString());
                }

                //返回true，代表事件不再向容器传播
                return true;
            }
        });
    }


}
